<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Auth;
class PasswordController extends Controller
{
	public function __construct ()
	{
		//由于构造函数优先被执行，所以我们再构造函数中调用框架自带的一个是否登录的中间件，如果登录了，中间件会放行
		$this->middleware('checkLogin');
	}

	public function changPassword(){
    	return view ('password');
	}
	public function password(Request $request,PasswordController $passwordController){
		//获取post数据
		$post = $request->all ();
		//获取当前用户的旧数据
		$user = Auth::user();
		$user->nickname = $post['nickname'];
		//判断密码是否填写
		if($post['password']){
			$user->password=bcrypt ($post['password']);
		}
		$user->save();
		session ()->flash ('success','修改成功');
		return redirect ('/');
	}
}
